package com.zhiwei.fast.fragments.models

import com.zhiwei.fast.R
import com.zhiwei.fast.data.RandomItem
import com.zhiwei.most.base.viewmodel.BaseViewModel
import com.zhiwei.most.data.SingleLiveData
import com.zhiwei.most.ext.launch

/**
 * Create by zhiweizhu on 2022/2/26
 */
class SweepstakesFragmentViewModel : BaseViewModel() {


    private val mLoopLiveData: SingleLiveData<MutableList<MutableList<RandomItem>>> by lazy(LazyThreadSafetyMode.NONE) {
        SingleLiveData()
    }

    fun getLoopLiveData(): SingleLiveData<MutableList<MutableList<RandomItem>>> {
        return mLoopLiveData
    }


    private val mRandomList = mutableListOf(
        R.mipmap.extra_red_envelope,
        R.mipmap.fixed_red_envelope,
        R.mipmap.extra_red_envelope,
        R.mipmap.fixed_red_envelope,
        R.mipmap.fixed_red_envelope,
        R.mipmap.extra_red_envelope,
        R.mipmap.fixed_red_envelope,
        R.mipmap.extra_red_envelope,
        R.mipmap.fixed_red_envelope
    )

    fun loadDataForNow(): MutableList<RandomItem>{
        var list = mutableListOf<RandomItem>()
        for (value in 0..10) {
            list.add(RandomItem(value, mRandomList.random()))
        }
        list.add(2, RandomItem(2, R.mipmap.ic_launcher_round))
        return list
    }


    fun loadData() {
        launch(
            {

                var list = mutableListOf<MutableList<RandomItem>>(
                    mutableListOf(),
                    mutableListOf(),
                    mutableListOf(),
                )

                for (value in 0..10) {
                    list[0].add(RandomItem(value, mRandomList.random()))
                    list[1].add(RandomItem(value, mRandomList.random()))
                    list[2].add(RandomItem(value, mRandomList.random()))
                }
                list
            },
            {
                getLoopLiveData().value = it
            },
            {
                it.printStackTrace()
            }
        )
    }

}
